package com.apes.scm.masterdata.product.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.scm.masterdata.product.model
 * @ClassName: CategorySupplyRange
 * @Author: pyb
 * @CreateTime: 2020-02-13 15:27
 * @Description: 品类直供范围
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CategorySupplyRange.CONST_TABLE_NAME)
public class  CategorySupplyRange extends Model {
    public static final String CONST_TABLE_NAME = "mas_category_supply_range";
    @Id
    @Column(name = "id", length = 6)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "品类直供编码", padding = 6)
    @Comment("品类直供编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("商品分类编码")
    private Classify classify;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("采购部门")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_id", referencedColumnName = "id")
    @Comment("品牌")
    private Brand brand;

    @Transient
    private String classifyId;

    @Transient
    private String classifyName;

    public String getClassifyId() {
       return this.classify.getId();
    }

    public String getClassifyName() {
        return this.classify.getName();
    }
}
